import axios from '@/utils/request'
export default {
  Role: {
    list: {
      list_filter: {
        'store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        }
      },
      list_display: [
        'store',
        'name',
        {
          property: 'categories',
          label: '可见产品分类',
          component: {
            props: ['data'],
            data() {
              return {
                categories: []
              }
            },
            created() {
              axios.get(`/manage/categories`, { params: { '@filter': `entity.getId() in [${this.data.toString()}]` }}).then((res) => {
                this.categories = res.data
                console.log('categories', res.data)
              })
            },
            render(h) {
              return (
                <div >
                  {
                    this.categories.map(v => {
                      return <div>{v.name}</div>
                    })
                  }
                </div>
              )
            }
          }
        },
        {
          property: 'defaultDailySalary',
          label: '默认日薪'
        },
        {
          property: 'defaultBond',
          label: '默认保证金'
        },
        {
          property: 'defaultOnboardFee',
          label: '默认入职费用'
        },
        'disableAutoOrderSettle'
      ]
    },
    form: {
      fields: [
        'store',
        'name',
        {
          property: 'categories',
          field_options: { label: '可见产品类型' },
          required: true,
          default_value: [],
          component: {
            props: ['form', 'property'],
            data() {
              return {
                categories: []
              }
            },
            created() {
              this.axios.get(`/manage/categories`, { params: { 'limit': 1000000 }}).then((res) => {
                const categories = []
                for (var i of res.data) {
                  categories.push({
                    label: `${i.name}[${i.store.__toString}]`,
                    key: i.id
                  })
                }
                this.categories = categories
              })
            },
            render(h) {
              return (
                <el-transfer v-model={this.form[this.property]} data={this.categories} titles={['未选', '已选']}></el-transfer>
              )
            }
          }
        },
        {
          property: 'defaultDailySalary',
          field_options: { label: '默认日薪' }
        },
        {
          property: 'defaultBond',
          field_options: { label: '默认保证金' }
        },
        {
          property: 'defaultOnboardFee',
          field_options: { label: '默认入职费用' }
        },
        {
          property: 'defaultExtraData',
          default_value: {
            isPrincess: false,
            isBooker: false,
            isCashier: false,
            canCashier: false,
            noStatistics: false,
            changeRoule: false,
            edit: false,
            canPenaltie: false,
            noCancelOrder: false,
            noChangeSquad: false,
            noChangeRole: false,
            attendanceOrder: false
          },
          field_options: { label: '角色默认权限' },
          help: 'noCancelOrder:不能取消订单 ；isPrincess:房间公主 ,isBooker: 可以订台,isCashier: 查看所有结算订单,canCashier: 可以统收订单,noStatistics: 不查看总报表,changeRoule: 队长经纪可修改下属信息,edit: 管理员可修改员工信息;attendanceOrder:不打卡不能下单'
        },
        {
          property: 'disableAutoOrderSettle',
          field_options: { label: '不自动分账' },
          help: '只是针对门店已经设置了自动分账的情况，对应角色不会执行自动分账，门店管理员可以执行手动分账'
        }
      ]
    }
  }
}

